package edu.msg.hrappy.api.resources;

import javax.ejb.DependsOn;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import edu.msg.hrappy.api.assembler.JobAssembler;
import edu.msg.hrappy.api.resources.exception.HrappyApiException;
import edu.msg.hrappy.backend.model.Job;
import edu.msg.hrappy.backend.service.JobService;

@LocalBean
@Stateless
@DependsOn ({"JobService","JobAssembler"})
@Path("/jobs")
@Produces (MediaType.APPLICATION_JSON)

public class JobResource {
	
	@EJB 
	private JobService jobService;
	@EJB
	private JobAssembler jobAssembler;
	
	@Path ("/{jobId}")
	@GET
	public Response getJob(@PathParam ("jobId") final Long jobId) throws HrappyApiException {
		final Job job = jobService.getById(jobId);
		if(job != null) {
			return Response.ok(jobAssembler.modelToDto(job)).build();
		} else {
			throw new HrappyApiException("Job not found!");
		}
	}

}
